<template>
  <div>
    <!-- 顶部组件 -->
    <header-nav></header-nav>
    <!-- 轮播图 -->
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in imgs" :key="index">
            <img :src="item.pic" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>

    <!-- swiper功能 -->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide item">
          <span class="iconfont icon-paixingbang"></span>
          <div class="icon-text">排行榜</div>
        </div>
        <div class="swiper-slide item">
          <span class="iconfont icon-zhibo"></span>
          <div class="icon-text">直播</div>
        </div>
        <div class="swiper-slide item">
          <span class="iconfont icon-pic3"></span>
          <div class="icon-text">数字专辑</div>
        </div>
        <div class="swiper-slide item">
          <span class="iconfont icon-youxitianchong"></span>
          <div class="icon-text">游戏</div>
        </div>
      </div>
      <!-- Add Pagination -->
      <div class="swiper-pagination"></div>
    </div>

    <!-- 推荐歌单 -->
    <div class="remLists">
      <div class="title">推荐歌单</div>
      <div class="content">
        <ul>
          <router-link tag="li" :to="'/rank/ranklist?id='+ item.id" v-for="(item, index) in songlist" :key="index" >
            <div class="img">
              <van-image lazy-load :src="item.picUrl" alt="" />
            </div>
            <p>{{ item.name }}</p>
            <span
              ><i class="iconfont icon-erji"></i
              >{{ item.playCount | playCountData }}</span
            >
          </router-link>
        </ul>
      </div>
    </div>

    <!-- 推荐MV -->
    <div class="remMv">
      <div class="title">推荐MV</div>
      <div class="content">
        <ul>
          <li
            @click="playMvFun(item.id, item.playCount)"
            class="item"
            v-for="item in mvlist"
            :key="item.id"
          >
            <div class="img">
              <van-image lazy-load :src="item.picUrl" alt="" />
            </div>
            <p>{{ item.name }}</p>
            <p >演出:<span v-for="el in item.artists" :key="el.id">{{el.name}}</span></p>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import headerNav from "../components/base/headerNav.vue";
import { getBanner } from "../api/recommend";
import { getPersonalizedr, getPersonalizedMv } from "../api/recommend";
import Swiper from "swiper";
export default {
  data() {
    return {
      imgs: null,
      songlist: null,
      mvlist: null, //推荐mv
      
    };
  },
  methods: {
    playMvFun(id, playCount) {
     
      this.$router.push({ name: "remMv", params: { id, playCount } });
    },
  },
  created() {
    getBanner().then((data) => {
      
      this.imgs = data.banners;

    });

    // 推荐歌单
    getPersonalizedr().then((data) => {
     
      this.songlist = data.result;
      
     });

    // 推荐mv
    getPersonalizedMv().then((data) => {
      
      this.mvlist = data.result;
    });
  },
  components: {
    headerNav,
  },

  mounted() {
    new Swiper(".swiper-container", {
      
      slidesPerView: 4,
      paginationClickable: true,
      
    });
  },

  // 过滤器
  filters: {
    playCountData(value) {
      let w = value > 10000 ? value / 10000 : value; //万计算
      let y = w > 10000 ? parseInt(w / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
};
</script>

<style lang="less">
// 轮播图
.banner {
  &::before {
    content: "";
    display: block;
    height: 124px;
    background-color: #d44439;
    position: absolute;
    width: 100%;
    z-index: -1;
  }
  position: relative;
  .imgs {
    position: relative;
    left: 0px;
    right: 0px;
    top: 0px;
    margin: auto;
    width: 96%;
    border-radius: 4px;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
}

// 歌单列表
.remLists {
  .title {
    height: 60px;
    line-height: 60px;
    text-align: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
    padding-left: 10px;
    box-sizing: border-box;
  }
  .content {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-evenly;
      li {
        flex: 0 0 31%;
        position: relative;
        span {
          position: absolute;
          top: 0px;
          right: 0px;
          color: #fff;
          font-size: 10px;
          i {
            font-size: 15px;
            vertical-align: middle;
          }
        }
        .img {
          min-height: 50px;
          width: 100%;
          border-radius: 3px;
          img {
            width: 100%;
            border-radius: 3px;
          }
        }
        p {
          font-size: 12px;
          color: #565658;
          line-height: 15px;
          padding: 5px;
          margin-bottom: 10px;
          height: 26px;
          overflow: hidden;
        }
      }
    }
  }
}

// 推荐mv
.remMv {
  .title {
    height: 60px;
    line-height: 60px;
    text-align: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
    padding-left: 10px;
    box-sizing: border-box;
  }
  .content {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-evenly;
      li {
        flex: 0 0 47%;
        position: relative;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        // background-color: red;
        // height: 120px;
        .img {
          // height: 90px;
          width: 100%;
          border-radius: 3px;
          img {
            width: 100%;
            height: 101px;
            border-radius: 3px;
          }
        }
        p {
          width: 100%;
          font-size: 14px;
          font-weight: bold;
          color: #565658;
          line-height: 15px;
          padding: 5px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }
      }
    }
  }
}

.swiper-wrapper {
  margin-top: 10px;
  .swiper-slide.item {
    // height: 30px;
    text-align: center;

    .iconfont {
      font-size: 25px;
      color: #d44439;
    }
    .icon-text {
      font-size: 14px;
    }
  }
}
</style>